/*  let a =1; 
 console.log(a);

 const fn = ()=>1;
 */


 /* let [a,b,c,d] =[1,2,3];
 console.log(a);
 console.log(b);
 console.log(c); */



 /* let [a,b="hzh"]=['胡子恒'];
 console.log(a,b); */



/* let [a,b="123"]=['胡子恒',null];
console.log(a,b); */



/*  let {foo,bar} = {bar:'胡子恒',foo:'hzh'};
 console.log(foo,bar); */



 /* function taiji(...arg) {
     console.log(arg[0]);
     console.log(arg[1]);
     console.log(arg[2]);
     console.log(arg[3]);
 }
 taiji(1,2,3); */



 /* function taiji(first,...arg) {
     console.log(arg,length);
     console.log(first);
     console.log(arg);

 }
 taiji(0,1,2,3,4,5,6,7); */



 /* let a ='小华';
 let b ='我是真的很喜欢你呀小华!';
 document.write(b.indexOf(a));
 document.write(b.includes(a));
 document.write(b.startsWith(a));
 document.write(b.endsWith(a));
 document.write('*'.repeat(3)); */


/*  let a =11/4;
 console.log(Number.isFinite(a));
  console.log(Number.isFinite('ll'));
 console.log(Number.isFinite(NaN));
 console.log(Number.isFinite(undefined));

 console.log(isFinite(NaN));
 console.log(isFinite(undefined));
 console.log(isFinite('taiji'));
 console.log(isFinite(123));
 console.log(isFinite(1000+'2a'));

 console.log(Number.isFinite(NaN));
 console.log(Number.isFinite(undefined));
 console.log(Number.isFinite('taiji'));
 console.log(Number.isFinite(123));
 console.log(Number.isFinite(1000+'2a'));

 console.log(parseInt("abc1111"));
 console.log(Number.isNaN(parseInt("abc1111"))); */



/*  let a =918.1;
 console.log(Number.isInteger(a));
 console.log(Number.parseInt(a,38));
 console.log(parseInt('0X0BAF3'));
 console.log(parseInt('0X0BAF3',16)); */



 /*
 let a = Math.pow(2,53)-1;
 console.log(a);
 console.log(Number.MAX_SAFE_INTEGER);
 console.log(Number.MIN_SAFE_INTEGER);
 console.log(Number.isSafeInteger(a)); */




 /* console.log(Number.isNaN(1/3));
  console.log(typeof(1/3));
 console.log(typeof 1/3); */




/*  let json ={
 '0':'lj',
 '1':'胡子恒',
 '2':'太极',
 length:3
 }
 console.log(json);
 let arr = Array.from(json);
 console.log(arr); */



/*  let arr =  Array.of(3,4,5,6);
 console.log(arr);
 let arr2 = Array.of('太极','hzh','开发者社区');
 console.log(arr2);
 */


/*  let arr = [1,2,3,4,5,6,7,8];
 var v = arr.find((value)=>{
        return value > 4;  
 }) ;
 console.log(v); */



/*  let arr1 = [1,2,3,4,5,6,7,8];
 var i = arr1.findIndex((value)=>value>4);
 console.log(i); */



 /* let arr2 = [1,2,3,4,5,6,7,8];
 var a= arr2.filter((value)=>value>4);
 console.log(a); */


/*  var add =(a,b=2) =>a+b;
 console.log(add(1,3));

 var add=(a,b=1) =>{
     console.log("taiji");
     return a+b;
 }
 console.log(add(1)); */




/*  let json = {
     a:'hzh',
     b:'123'
 }
 function fun({a,b='web'}) {
     console.log(a,b);
 }
 fun(json);
 */

/* 
 let json = {
     a:'lj',
     b:null
 }
 function fun({a,b='web'}) {
     console.log(a,b);
 }
fun(json); */

/* 
 let arr=[,,];
 console.log(arr.length);
 console.log(0 in arr); */


/*  let arr =['ll','胡子恒','taiji'];
 arr.forEach((val,index)=>console.log(index,val)); */


 /* let arr =['ll','胡子恒','taiji'];
 arr.some(x=> console.log(x)); */


 /* let arr =['ll','胡子恒','taiji'];
 console.log(arr.map(x=>'web')); */




 /* let name = "lj";
 let skill = 'web';
 var obj = {name,skill};
 console.log(obj); */




/*  let key="skill";
 var obj = {
     [key]:'skill'
 }
 console.log(obj[key]); */



 /* let obj1={name:'ll'};
 let obj2={name:'ll'};
 console.log(obj1.name===obj2.name);
 console.log(Object.is(obj1.name,obj2.name)); */



//------------------------------------------------------------------------------------------------
//     ===同值相等    is严格相等
//     ==：相等[如果两边类型不一样，首先会隐式转化为相同的类型，然后再做比较]
//     对象 == 字符串 对象->字符串
//     null == undefined ->true  [三个等号是不相等的，但是null/undefined和其它任何值都不会相等]
//     NaN === NaN ->false
//     Symbol() === Symbol() ->false
//     剩余的情况[例如:对象==数字、字符串==布尔...]都是要转换为数字，再进行比较
//     ===：绝对相等[要求两边的类型和值都要相等]


//     规则：只有""0、null、undefined、空字符串"会变为false，
//     其余都是转换为true         [] ->true         ![] -> false
//--------------------------------------------------------------------------------------------------



//     console.log(+0===-0);
//     console.log(NaN===NaN);
//     console.log(Object.is(+0,-0));
//     console.log(Object.is(NaN,NaN));//Object.is是比较是否为同一个值



//assign合并
// let a ={a:'lj'};
// let b ={b:'胡子恒'};
// console.log(Object.assign(a,b));



//Symbol
// let a = new String;
// let b= new Number;
// let c= new Boolean;
// let d=new Array;
// let f=new Object;
// let g=Symbol();
// console.log(typeof(g));


//Symbol的打印 对象的唯一属性
// let lll = Symbol('噜啦啦');
// console.log(lll);
// console.log(lll.toString());

// let n= Symbol('AA');
// let m=Symbol('AA');
// console.log(n === m );//false

// //Symbol在对象中的应用
// let ll = Symbol();
// let obj = {
//     [ll]:'噜啦啦'
// };
// console.log(obj[ll]);

//Symbol在对象中保护应用
// let obj ={name:'ll',skill:'web'};
// let age = Symbol();
// obj[age]=18;
// console.log(obj);
// for (let item in obj) {
//    console.log(obj[item]);
//     }



//set的声明
// let setArr = new Set(['lj','胡子恒','web']);
// setArr.add('前端技术');
// console.log(setArr);

//去重
// let arr=[1,2,3,4,5,6,2,3,4,1,2,1,5,4];
// let newSet=[...new Set(arr)];
// console.log(newSet);

//循环输出
// for.. of
// for (let item of setArr) {
// console.log(item);
// }

//foreach
//  setArr.forEach((value) =>console.log(value) );
//  console.log(setArr.size);

// const s = new Set();
// [2,3,1,4,5,6,8,2,3,6,5,4,1].forEach(x=>s.add(x));
// console.log([...s]);//去重
// for (let i of s) {
// console.log(i);
// }



//WeakSet的声明
// let weakObj=new WeakSet();
// let obj={a:'ll',b:'噜啦啦'};
// let obj2={a:'ll',b:'噜啦啦'};
// weakObj.add(obj);
// weakObj.add(obj2);
// console.log(weakObj);



//map数据类型
// json
// let json={
// name:'ll',
// skill:'web'
// };
// console.log(json.name);

// var map=new Map();
//  map.set(json,'i am');
//  console.log(map);

// map.set('ll',json);
// console.log(map)


//map增删改
//get 取值
// console.log(map.get(json));
//delete 删除特定的值
// map.delete(json);
// console.log(map);  


//clear 删除全部的值
//map.clear();
//console.log(map);

   
// const myMap=new Map().set(true,7).set({foo:3},['abc']);
// const arr =[...myMap];//map转数组(第一种)
// const arr2=Array.from(myMap); //map转数组(第二种)
// console.log(arr2);



// let obj ={
// add:function (val) {
// return val+100;
//     },
// name:'i am lj'
// }
// console.log(obj.add(100));
// console.log(obj.name);



    // const employee={
    //     firstName:'liang',
    //     lastName:'juan'
    // };

    // console.group('employee')
    // console.log(employee.firstName);
    // console.log(employee.lastName);
    // console.log(employee.org);
    // console.log(employee.fullName);


    // let handler={
    //     get: function(target,fieldName){
    //         if(fieldName === 'fullName'){
    //             return `${target.firstName} ${target.lastName}`;
    //         }
    //         return fieldName in target ?target[fieldName]:`No such property as ${target.fieldName}`;
    //     }
    // };
    // let p = new Proxy(employee,handler);


    // console.group('proxy');
    // console.log(p.firstName);
    // console.log(p.lastName);
    // console.log(p.org);
    // console.log(p.fullName);
    // console.groupEnd;



//改变set方法来实现一个验证的例子  此案件一个handler，重新命名为validator
    // const validator={
    //     set:function(obj,prop,value) {
    //         if (prop ==='age') {
    //             if (!Number.isInteger(value)) {
    //                 throw new TypeError('age is always an integer , please correct it ');
    //             }
    //             if (value<0) {
    //                 throw new TypeError('this is insame , a negative age?');
    //             }
    //         }
    //     }
    // };
    // //然后再建一个Proxy
    // let pr = new Proxy(employee,validator);
    // //设置一个不合法的属性
    // // pr.age='test';
    // pr.age=-2;
    // // pr.age= 2;



    // var pro=new Proxy({
    //         add:function(val){
    //             return val+100
    //         },
    //         name:'i am lj',
    // },{
    //     //get
    //     get:function(target,key,value,recriver){
    //         console.log('come in GET');
    //         return target[key];
    //     },
    //     //set
    //     set:function(target,key,value,recriver){
    //         console.log(`setting ${key} = ${value}`);
    //         return target[key]=value +'222';
    //     }
    // });
    // // pro.name='廖荣华';
    // // console.log(pro.name);
    // console.log(pro.add(6));



    //promise
    //promise ES5 

    // let state = 1;
    // function step1(resolve,reject) {
    //     console.log('1.开始洗菜做饭');
    //     if (state==1) {
    //         resolve('洗菜做饭');
    //     }else{
    //         reject('洗菜做饭---错误');
    //     }
    // }

    // function step2(resolve,reject) {
    //     console.log('2.开始吃饭');
    //     if (state==1) {
    //        resolve('开始吃饭');
    //     }else{
    //         reject('吃饭---错误');
    //     }
    // }

    // function step3(resolve,reject) {
    //     console.log('3.开始收拾桌子');
    //     if (state==1) {
    //         resolve('收拾桌子');
    //     }else{
    //         reject("收拾桌子---错误");
    //     }
    // }

    // new Promise(step1).then(function(val){
    //      console.log(val);
    //      return new Promise(step2);
    // }).then(function(val){
    //     console.log(val);
    //     return new Promise(step3);
    // }).then(function(val){
    //       console.log(val);
    // });

    